package com.flame.schedule.controller;

import java.util.List;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.schedule.controller.vo.JobLogVo;
import com.flame.schedule.entity.JobLog;
import com.flame.schedule.service.JobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_schedule_job_log 任务信息表
 *
 * @author 吴欣童
 * @since 2022-12-04 12:47:08
 */
@RestController
public class JobLogController {

    @Autowired
    private JobLogService jobLogService;

    @HasAuth("job-log")
    @PostMapping("/schedule/log/page")
    public PageResult pageJobLog(@RequestBody JobLogVo jobLogVo) {
        return PageResult.success(jobLogService.pageJobLog(jobLogVo));
    }

    @HasAuth("job-log:delete")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/schedule/log/delete")
    public Result deleteJobLog(@RequestBody @Validated JobLog jobLog) {
        jobLogService.deleteJobLog(jobLog);
        return Result.success();
    }

    @HasAuth("job-log:batch-delete")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/schedule/log/batch-delete")
    public Result batchDeleteJobLog(@RequestBody List<Long> logIdList) {
        jobLogService.batchDelete(logIdList);
        return Result.success();
    }

    @HasAuth("job-log:clear")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/schedule/log/clear")
    public Result clearLog() {
        jobLogService.clear();
        return Result.success();
    }
}
